#include "Screen.hpp"

namespace yep
{

Screen *Screen::instance = NULL;

Screen & Screen::getInstance()
{
	if(!instance)
		instance = new Screen;
	return *instance;
}

Screen::Screen() :
		Canvas(NULL, false)
{
}

Screen::~Screen()
{
}

void Screen::setVideoMode(int width, int height, int bpp, int flags)
{
	surface = SDL_SetVideoMode(width, height, bpp, flags);
	YEP_ERROR_TEST(surface, SDL_GetError());
}

void Screen::setFullScreen(bool full)
{
	Uint32 flags = surface->flags;

	if (full)
	{
		flags |= SDL_FULLSCREEN;
	}
	else
	{
		flags = ~(~flags | SDL_FULLSCREEN);
	}

	setVideoMode(getWidth(), getHeight(), surface->format->BitsPerPixel, flags);
}

bool Screen::isFullScreen() const
{
	return surface->flags & SDL_FULLSCREEN;
}

void Screen::flip()
{
	SDL_Flip(surface);
}

string Screen::getCaption() const
{
	char *caption;
	SDL_WM_GetCaption(&caption, NULL);
	return string(caption);
}

void Screen::setCaption(const string & value)
{
	SDL_WM_SetCaption(value.c_str(), NULL);
}

bool Screen::initialized() const
{ return surface; }

}

